package com.examination.client.controller;

import com.examination.client.annotation.PassToken;
import com.examination.client.service.IAliyunOssService;
import com.examination.client.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;


/**
 * @author xiaodong
 * @Description:
 * @Date: 2021/10/20
 */

@Slf4j
@RestController
@RequestMapping("/oss")
@Api(tags = "文件上传")
@CrossOrigin(origins = "*")
public class UploadController {

    @Resource
    IAliyunOssService aliyunOssService;

    @PostMapping("/upload/{courierCode}/{courierStatus}")
    @ApiOperation("文件上传-存图片到数据库")
    @PassToken
    public Result<String> toUploadBlogPost(@RequestParam ("file") MultipartFile file,
                                           @PathVariable ("courierCode") String courierCode,
                                           @PathVariable ("courierStatus") String courierStatus) throws Exception {
        return Result.success(aliyunOssService.upload(file, courierCode, courierStatus));
    }

    @PostMapping("/upload")
    @ApiOperation("文件上传")
    public Result<String> toUploadPost(@RequestParam ("file") MultipartFile file) throws Exception {
        return Result.success(aliyunOssService.upload(file, "0", "0"));
    }

    @PostMapping("/uploadAsy")
    @ApiOperation("文件上传")
    public Result<String> toUploadPostAsy(@RequestParam ("file") MultipartFile file, @RequestParam("id") String id) throws Exception {
        return Result.success(aliyunOssService.uploadAsy(file, id));
    }

    @PostMapping("/uploadAsyCode")
    @ApiOperation("文件上传")
    public Result<String> toUploadAsyCode(@RequestParam ("file") MultipartFile file, @RequestParam("code") String code) throws Exception {
        return Result.success(aliyunOssService.uploadAsyCode(file, code));
    }

}
